//package ai.people.netmon.gateway.filter;
//
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.http.HttpHeaders;
//import org.springframework.http.HttpMethod;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.server.reactive.ServerHttpRequest;
//import org.springframework.http.server.reactive.ServerHttpResponse;
//import org.springframework.web.cors.reactive.CorsUtils;
//import org.springframework.web.server.ServerWebExchange;
//import org.springframework.web.server.WebFilter;
//import org.springframework.web.server.WebFilterChain;
//import reactor.core.publisher.Mono;
//
///**
// * 安全规则过滤器
// *
// * @author yuanqinglong
// * @date 2022/04/07
// */
//@Slf4j
////@RequiredArgsConstructor
////@Order(Ordered.HIGHEST_PRECEDENCE)
////@Configuration(proxyBeanMethods = false)
//public class SecurityRuleFilter implements WebFilter {
//
//
//    @Override
//    @SuppressWarnings("all")
//    public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
//        //增加CORS
//        //解决前端登录跨域的问题
//        ServerHttpRequest request = exchange.getRequest();
//        if (CorsUtils.isCorsRequest(request)) {
//            log.info("cros request : {}", request.getHeaders().getOrigin());
//            ServerHttpResponse response = exchange.getResponse();
//            HttpHeaders headers = response.getHeaders();
//            headers.add("Access-Control-Allow-Origin", "*");
//            headers.add("Access-Control-Allow-Methods", "*");
//            headers.add("Access-Control-Max-Age", "3600");
//            headers.add("Access-Control-Allow-Headers", "*");
//            headers.add("Access-Control-Allow-Credentials", "true");
//            if (request.getMethod() == HttpMethod.OPTIONS) {
//                response.setStatusCode(HttpStatus.OK);
//                return Mono.empty();
//            }
//        }
//        return chain.filter(exchange);
//    }
//
//}
